<?php

namespace App\Modules\LuckDraw\Award;

use App\Modules\LuckDraw\Lib\StrLib;

class AwardFactory {

    //获取一个奖品实例
    public static function get(
        int $luckId,
        int $userId,
        int $type,
        int $rewardId,
        int $timeLimit,
        int $price
    ) : ?AwardInterface {
        $className = self::_getAwardClassNameByType($type);
        if ($className == '') {
            return null;
        }
        $className = __NAMESPACE__ . '\\' . StrLib::camelize($className) . 'Award';
        if(class_exists($className)){
            return new $className($luckId, $userId, $rewardId,$timeLimit, $price);
        }
        return null;
    }

    private static function _getAwardClassNameByType(int $type):string{
        $className = "";
        switch ($type)
        {
            case 0:
                $className = "empty";
                break;
            case 1:
                $className = "gift";
                break;
            case 2:
                $className = "goods";
                break;
            case 3:
                $className = 'gift_pearl';
                break;
            default:
                $className = '';
                break;
        }
        return $className;
    }
}